// 测评用户BMI指数

$(function() {

	var inputdata = $("#inputdata");
    var measuredata = $("#measuredata");
    var weight = $("#weight");
    var high = $("#high");
    var bmi_div = $("#bmi_div");
    var bmi = $("#bmi");
    var bmi_val = null;
    var bmi_meas = null;

    measuredata.on("click", function() {
        bmi_div.show();
        bmi_val = Math.round(weight.val() / ((high.val()/100) * (high.val()/100))*100)/100;
        if(bmi_val<18.5)
        	bmi_meas="过轻";
        else if(bmi_val<23.9)
        	bmi_meas="正常";
        else if(bmi_val<27)
        	bmi_meas="过重";
        else
        	bmi_meas="肥胖";

        if(weight.val() === "" || high.val() === "")
        	bmi.val("您还没有输入喔");
        else
        	bmi.val(bmi_val+" "+bmi_meas);
    });

    inputdata.keyup(function(e){
    	if(e.keyCode==13){
    		measuredata.click();
    	}
    });

    weight.on("focus",function(){
        bmi_div.hide();
    });

    high.on("focus",function(){
        bmi_div.hide();
    });

});